N=int(raw_input())
nums=map(int, raw_input().split(' '))
sortednums=nums[:]
sortednums.sort()

zhuyuans = []
for e in range(N):
    if nums[e]==sortednums[e]:
        zhuyuans.append(nums[e])

print len(zhuyuans)
print ' '.join(map(str, zhuyuans))